package com.g001.enums;

import java.util.Random;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public enum BlockType {
	BORDER(0,0,0, 0,false,false),
	ATTACK(1,164,0,10,true,true),
	SHIELD(2,82,0,10,true,true),
	HEALTH(3,328,0,5,true,true),
	SPECIAL_ADD(4,246,0,15,true,true),
	SPECIAL_DEL(5,0,0,35,true,true),
	MAGIC_ADD(6,410,0,10,true,true),
	MAGIC_DEL(7,246,69,5,true,true),
	STRIKE_BACK(8,0,69,5,true,true),
	BONUS(9,164,69,0,true,true)
	;
	
	private static Image imgRess = null;
	private static Image[] blocksImg = new Image[BlockType.values().length];
	private final static Random random = new Random();
	
	public static final float TRANSPARENT_BODER_X = 4;
	public static final float TRANSPARENT_BODER_Y = 4;
	// border of the shape of the polygon of a block
	public static final float tab[] = {21f,2f, 59f,2f, 76f,32f, 57f,64f, 20f,63f, 2f,32f};
	
	
	
	static {
		try {
			imgRess = new Image("res/data/g001/blocks.png");
			for(BlockType bt : BlockType.values()) {
				blocksImg[bt.id] = imgRess.getSubImage(bt.getWidth(), bt.getHeight(), BlockType.WIDTH, BlockType.HEIGHT);
			}
		} catch (SlickException e) {			
			e.printStackTrace();
		}
	}
	
	public final static int WIDTH =  81;//79;
	public final static int HEIGHT = 69; // 66;
	public final static float PULSE_MIN = 1.02f;
	public final static float PULSE_MAX = 1.15f;
	
	public final static int SHOCK_ON_X = 4;
	public final static int SHOCK_ON_Y = 4;
	public final static long SHOCK_DURATION = 500;  
	public final static long DESTROYED_DURATION = 2000;
	public final static long BLOCK_SPAWN_TIME = 80; 
	public final static float PULSE_INTERVAL = 0.0004f;
	public final static float INIT_SPEED = 0.2f; //0.125f;
	
	public final static float EXPLOSE_MIN = 0.006f;
	
	private int id;
	private int height;
	private int width;
	private int potionX;
	private int potionY;
	private boolean movable;
	private boolean visible;
	private int points;
	
	private BlockType(final int id, final int w, final int h, final int points, final boolean movable, final boolean visible) {
		this.id = id;
		this.movable = movable;
		this.visible = visible;
		height = h;
		width = w;
		this.points = points;
	}

	public int getId() {
		return id;
	}
	
	public boolean isVisible(){
		return visible;
	}
	
	public int getPoints(){
		return points;
	}

	public static BlockType getBlockType(final int id) {
		switch(id) {
			case 0 : return BORDER; 
			case 1 : return ATTACK; 
			case 2 : return SHIELD; 
			case 3 : return HEALTH; 
			case 4 : return SPECIAL_ADD; 
			case 5 : return SPECIAL_DEL; 
			case 6 : return MAGIC_ADD; 
			case 7:  return MAGIC_DEL; 
			case 8:  return STRIKE_BACK;
			case 9:  return BONUS;
			default :throw new IllegalArgumentException("no id ("+id+") affected to any Block type");
		}
	}
	
	public static BlockType getRandomBlockType(){
		return getBlockType(1+random.nextInt(BlockType.values().length-1)); // ALL BLOCKS but not BORDER
	}
	

	public int getHeight() {
		return height;
	}

	public int getWidth() {
		return width;
	}
	
	public Image getImage(){
		return blocksImg[this.id];
	}
	
	
	public boolean isMovable(){
		return movable;
	}

	public int getPotionX() {
		return potionX;
	}

	public void setPotionX(int potionX) {
		this.potionX = potionX;
	}

	public int getPotionY() {
		return potionY;
	}

	public void setPotionY(int potionY) {
		this.potionY = potionY;
	}
	

}
